import lombok.AllArgsConstructor;
import lombok.SneakyThrows;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;

@AllArgsConstructor
public class ReplyThread extends Thread {
 
    private Socket socket;

    private String name;
 
    @SneakyThrows
    @Override
    public void run() {
        // 接收socket里面的信息
        BufferedReader reply=new BufferedReader(new InputStreamReader(socket.getInputStream()));
        // 创建打印流，打印到控制台
        PrintStream output = System.out;
        do {
            // reply缓存里面读取信息
            String replyMsg = name + ": " + reply.readLine();
            // 输出到打印流
            output.println(replyMsg);
            if("Esc".equals(replyMsg)) break;
        } while(true);
        synchronized (Port.lock) {
            Port.lock.notify();
        }
    }
}